<?php 

namespace Index\Controller;
use Think\Controller;

/**
* 
*/
class DynamicController extends Controller
{
	//最新动态 
	public function index(){
		$link =M();
		$sql ="select u.username,u.head_img,a.content,q.title,q.id,q.replay from answer_collection c left join answer a on a.id=c.aid  left join user u on u.id=a.uid left join question q on q.id=a.qid where c.uid={$_SESSION['id']}";
		// var_dump($sql);
		$data =$link->query($sql);
		$this->assign('data',$data);
		// var_dump($data);
		$this->display();
	}


	//我的收藏
	public function collection(){
		$link =M();
		$sql ="select c.aid,a.content,q.title,q.id,u.username,u.head_img from answer_collection c left join answer a on c.aid=a.id left join question q on q.id=a.qid left join user u on a.uid=u.id where c.uid={$_SESSION['id']}";
		$data =$link->query($sql);
		// var_dump($data);
		$this->assign('data',$data);

		$this->display();
	}


	//取消收藏
	public function collection_cancel(){
		if ($_GET) {
			$id =$_GET['id'];//要取消的收藏的id
			$uid =$_SESSION['id'];
			$link =M();
			$sql ="delete from answer_collection where aid={$id} and uid={$uid}";
			// var_dump($sql);exit;
			$data =$link->execute($sql);
			// var_dump($data);exit;
			$this->success('取消成功!',U('index/dynamic/collection'));
		}
	}
	
}








 ?>